<template>
  <Form ref="formInline" :model="formInline" :rules="ruleInline"  style="padding:15% 40%">
    <Form-item prop="user">
      <Input type="text" v-model="formInline.user" placeholder="Username">
      <Icon type="ios-person-outline" slot="prepend"></Icon>
      </Input>
    </Form-item>
    <Form-item prop="password">
      <Input type="password" v-model="formInline.password" placeholder="Password">
      <Icon type="ios-locked-outline" slot="prepend"></Icon>
      </Input>
    </Form-item>
    <Form-item>
      <Button type="primary" @click="handleSubmit('formInline')">登录</Button>
    </Form-item>
  </Form>
</template>
<script>

  import VuexStore from '../vuex/store'

  export default {
    data () {
      return {
        formInline: {
          user: '',
          password: ''
        },
        ruleInline: {
          user: [
            { required: true, message: '请填写用户名', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请填写密码', trigger: 'blur' },
            { type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      handleSubmit (name) {
        this.$refs[name].validate((valid) => {
          if (!valid) {
            return this.$Message.error('表单验证失败!')
          }
          let obj = {}
          obj.logged = true
          this.$Message.success('提交成功!')
          this.$store.dispatch('is_logged', obj)
          this.$router.push({ path: '/shop_list' })
//            sessionStorage.setItem('user', JSON.stringify(this.formInline.user))
        })
      }
    },
    store: VuexStore
  }
</script>
